C
C     ..................................................................
C
C        SUBROUTINE DET3
C
C        PURPOSE
C           TO COMPUTE A VECTOR OF DERIVATIVE VALUES GIVEN A VECTOR OF
C           FUNCTION VALUES WHOSE ENTRIES CORRESPOND TO EQUIDISTANTLY
C           SPACED ARGUMENT VALUES.
C
C        USAGE
C           CALL DET3(H,Y,Z,NDIM,IER)
C
C        DESCRIPTION OF PARAMETERS
C           H     -  CONSTANT DIFFERENCE BETWEEN SUCCESSIVE ARGUMENT
C                    VALUES (H IS POSITIVE IF THE ARGUMENT VALUES
C                    INCREASE AND NEGATIVE OTHERWISE)
C           Y     -  GIVEN VECTOR OF FUNCTION VALUES (DIMENSION NDIM)
C           Z     -  RESULTING VECTOR OF DERIVATIVE VALUES (DIMENSION
C                    NDIM)
C           NDIM  -  DIMENSION OF VECTORS Y AND Z
C           IER   -  RESULTING ERROR PARAMETER
C                    IER = -1  - NDIM IS LESS THAN 3
C                    IER =  0  - NO ERROR
C                    IER =  1  - H = 0
C
C        REMARKS
C           (1)   IF IER = -1,1, THEN THERE IS NO COMPUTATION.
C           (2)   Z CAN HAVE THE SAME STORAGE ALLOCATION AS Y. IF Y IS
C                 DISTINCT FROM Z, THEN IT IS NOT DESTROYED.
C
C        SUBROUTINES AND FUNCTION SUBPROGRAMS REQUIRED
C           NONE
C
C        METHOD
C           IF X IS THE (SUPPRESSED) VECTOR OF ARGUMENT VALUES, THEN
C           EXCEPT AT THE ENDPOINTS X(1) AND X(NDIM), Z(I) IS THE
C           DERIVATIVE AT X(I) OF THE LAGRANGIAN INTERPOLATION
C           POLYNOMIAL OF DEGREE 2 RELEVANT TO THE 3 SUCCESSIVE POINTS
C           (X(I+K),Y(I+K)) K = -1,0,1.  (SEE HILDEBRAND, F.B.,
C           INTRODUCTION TO NUMERICAL ANALYSIS, MC-GRAW-HILL, NEW YORK/
C           TORONTO/LONDON, 1956, PP.82-84.)
C
C     ..................................................................
C
      SUBROUTINE DET3(H,Y,Z,NDIM,IER)
C
C
      DIMENSION Y(1),Z(1)
C
C        TEST OF DIMENSION
      IF(NDIM-3)4,1,1
C
C        TEST OF STEPSIZE
    1 IF(H)2,5,2
C
C        PREPARE DIFFERENTIATION LOOP
    2 HH=.5/H
      YY=Y(NDIM-2)
      B=Y(2)+Y(2)
      B=HH*(B+B-Y(3)-Y(1)-Y(1)-Y(1))
C
C        START DIFFERENTIATION LOOP
      DO 3 I=3,NDIM
      A=B
      B=HH*(Y(I)-Y(I-2))
    3 Z(I-2)=A
C        END OF DIFFERENTIATION LOOP
C
C        NORMAL EXIT
      IER=0
      A=Y(NDIM-1)+Y(NDIM-1)
      Z(NDIM)=HH*(Y(NDIM)+Y(NDIM)+Y(NDIM)-A-A+YY)
      Z(NDIM-1)=B
      RETURN
C
C        ERROR EXIT IN CASE NDIM IS LESS THAN 3
    4 IER=-1
      RETURN
C
C        ERROR EXIT IN CASE OF ZERO STEPSIZE
    5 IER=1
      RETURN
      END
